#########################################################################
# Makefile for jpegoptim
#
#
Version = 1.5.5
PKGNAME = jpegoptim

SHELL = /bin/sh

DEFS = @DEFS@

srcdir = @srcdir@
VPATH = @srcdir@

prefix = @prefix@
exec_prefix = @exec_prefix@
datarootdir = @datarootdir@
datadir = @datadir@

# Where to install the executables.
bindir = @bindir@

# Where to put libraries
libdir = @libdir@

# Where to put the Info files
infodir = @infodir@

# Where to put the manual pages.
mandir = @mandir@



CC        = @CC@
XCPPFLAGS = @CPPFLAGS@
CFLAGS    = @CFLAGS@ $(XCPPFLAGS) $(DEFS)
ifeq ($(CC),gcc)
CFLAGS	 += -Wall -Wformat -Werror=format-security
#CFLAGS  += -no-omit-frame-pointer -D_FORTIFY_SOURCE=2
#CFLAGS	 += -fstack-protector --param=ssp-buffer-size=4 -fsanitize=address,undefined
endif
LDFLAGS   = @LDFLAGS@
LIBS      = @LIBS@
STRIP     = strip

PYTHON ?= python3

INSTALL = @INSTALL@
INSTALL_DATA = @INSTALL_DATA@
INSTALL_PROGRAM = @INSTALL_PROGRAM@

@SET_MAKE@

# should be no reason to modify lines below this
#########################################################################

DIRNAME = $(shell basename `pwd`)
DISTNAME  = $(PKGNAME)-$(Version)

OBJS = $(PKGNAME).o jpegdest.o jpegsrc.o jpegmarker.o misc.o @GNUGETOPT@

.PHONY: test

all:	$(PKGNAME)

dssim.o:	dssim.c
	$(CC) $(CFLAGS) -std=c99 -c

$(PKGNAME):	$(OBJS)
	$(CC) $(CFLAGS) -o $(PKGNAME) $(OBJS) $(LDFLAGS) $(LIBS)


strip:
	for i in $(PKGNAME) ; do [ -x $$i ] && $(STRIP) $$i ; done

clean:
	rm -f *~ *.o core a.out make.log \#*\# $(PKGNAME) $(OBJS)

clean_all: clean
	rm -f Makefile config.h config.log config.cache config.status

dist:	clean_all
	(cd .. ; tar cvzf $(DISTNAME).tar.gz $(DIRNAME))

backup:	dist

archive:
	git archive --format tar --prefix ${DISTNAME}/ -o ../${DISTNAME}.tar master
	gzip -v -9 ../${DISTNAME}.tar


install: all install.dirs install.man
	$(INSTALL) -m 755 $(PKGNAME) $(DESTDIR)$(bindir)/$(PKGNAME)

printable.man:
	groff -Tps -mandoc ./$(PKGNAME).1 >$(PKGNAME).ps
	groff -Tascii -mandoc ./$(PKGNAME).1 | tee $(PKGNAME).prn | sed 's/.//g' >$(PKGNAME).txt

install.man: install.dirs
	$(INSTALL) -m 644 $(PKGNAME).1 $(DESTDIR)$(mandir)/man1/$(PKGNAME).1

install.dirs:
	$(INSTALL) -d -m 755 $(DESTDIR)$(mandir)/man1
	$(INSTALL) -d -m 755 $(DESTDIR)$(bindir)

# a tradition !
love:
	@echo "Not War - Eh?"

spell:
	codespell -S .git -S tools

test:	all
	(cd test && $(PYTHON) test.py -v)

# eof
